#include <ros/ros.h>
#include <turtlesim/Spawn.h>

int main(int argc,char** argv)
{

	ros::init(argc,argv,"turtle_spawn");
	ros::NodeHandle node;//创建节点句柄
	ros::service::waitForService("/spawn");
	
	ros::ServiceClient add_turtle = node.serviceClient<turtlesim::Spawn>("/spawn");
	
	//初始化turtlesim::Spawn的类型的数据
	turtlesim::Spawn srv;
	srv.request.x=2.0;
	srv.request.y=2.0;
	srv.request.name = "turtle2";
	
	//请求服务调用-打印服务端的消息数据
	ROS_INFO("Service to spawn turtle[x:%0.6f ,y:%0.6f ,name:%s]",srv.request.x,srv.request.y,srv.request.name.c_str());
	
	add_turtle.call(srv);//阻塞式等待反馈
	
	//显示服务调用结果
	ROS_INFO("Spawn turtle [name:%s]",srv.request.name.c_str());
	return 0;
	
}
